﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RedHouse.Data.Base;
using RedHouse.Data.Service;

namespace RedHouse.AdminControl.UserControls.Customer
{
    public partial class UCEmailList : System.Web.UI.UserControl
    {
        private ISubcribeService _subcribeService;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                List<int> pageSizeList = new List<int>() {25, 50, 100, 150, 200, 250 };
                ddlPageSize.DataSource = pageSizeList;
                ddlPageSize.DataBind();
            }
        }

        private void Initialize()
        {
            _subcribeService = new SubcribeService();
            ListView1.DataSource = _subcribeService.GetAllSubcribe().OrderByDescending(s => s.CreatedDate).ToArray();
            ListView1.DataBind();

        }

        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlPageSize = sender as DropDownList;
            DataPagerEmails.PageSize = int.Parse(ddlPageSize.SelectedValue);
        }

        protected void CurrentRowTextBox_OnTextChanged(object sender, EventArgs e)
        {
            TextBox t = (TextBox)sender;
            DataPagerEmails.SetPageProperties(Convert.ToInt32(t.Text) - 1,
                 DataPagerEmails.PageSize, true);
        }

        protected void DataPagerEmails_PreRender(object sender, EventArgs e)
        {
            Initialize();
        }
    }
}